package edu.zut.hb.ambition.drugstore.spring.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import common.annotation.Log;
import common.core.controller.BaseController;
import common.core.domain.AjaxResult;
import common.enums.BusinessType;
import com.ruoyi.system.domain.Drugstore;
import com.ruoyi.system.service.IDrugstoreService;
import common.utils.poi.ExcelUtil;
import common.core.page.TableDataInfo;


@RestController
@RequestMapping("/system/drugstore")
public class DrugstoreController extends BaseController
{
    @Autowired
    private IDrugstoreService drugstoreService;


    @PreAuthorize("@ss.hasPermi('system:drugstore:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drugstore drugstore)
    {
        startPage();
        List<Drugstore> list = drugstoreService.selectDrugstoreList(drugstore);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:drugstore:export')")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drugstore drugstore)
    {
        List<Drugstore> list = drugstoreService.selectDrugstoreList(drugstore);
        ExcelUtil<Drugstore> util = new ExcelUtil<Drugstore>(Drugstore.class);
        util.exportExcel(response, list, "仓库数据");
    }


    @PreAuthorize("@ss.hasPermi('system:drugstore:query')")
    @GetMapping(value = "/{rugstoreid}")
    public AjaxResult getInfo(@PathVariable("rugstoreid") Long rugstoreid)
    {
        return AjaxResult.success(drugstoreService.selectDrugstoreByRugstoreid(rugstoreid));
    }

    @PreAuthorize("@ss.hasPermi('system:drugstore:add')")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drugstore drugstore)
    {
        return toAjax(drugstoreService.insertDrugstore(drugstore));
    }


    @PreAuthorize("@ss.hasPermi('system:drugstore:edit')")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drugstore drugstore)
    {
        return toAjax(drugstoreService.updateDrugstore(drugstore));
    }

    @PreAuthorize("@ss.hasPermi('system:drugstore:remove')")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rugstoreids}")
    public AjaxResult remove(@PathVariable Long[] rugstoreids)
    {
        return toAjax(drugstoreService.deleteDrugstoreByRugstoreids(rugstoreids));
    }
}
